home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / doom / turric03.zip / TURRIC03.ZIP / PROGS / TRACBEAM.QC < prev    next >
Text File  |  1997-01-09  |  6KB  |  219 lines

  1. /*
  2. ==============================================================================
  3.  
  4. TRACTOR BEAM
  5.  
  6. ==============================================================================
  7. This is based on the tracbeam patch by Jonathan Avraham aka Procedure aka
  8. Shambler, procedure@hotmail.com, but has been almost completely
  9. reprogrammed by Turrican.
  10. */
  11.  
  12. void() TracbeamThink =
  13. {
  14.     local    vector    newpos, checkpoint;
  15.     local    float    dist, min_dist;
  16.  
  17.     if(self.owner.tracbeam_time <= time)
  18.     {
  19.         self.owner.tracbeam_status = TRACBEAM_OFF;
  20.         self.victim.nextthink = time;
  21. // Force released victims to fall.
  22. //        self.victim.velocity = '0 0 -50';
  23.         remove(self);
  24.         return;
  25.     }
  26.  
  27.     self.victim.nextthink = time + 0.3;
  28.  
  29. // Find point to move victim to.
  30.     makevectors(self.owner.v_angle);
  31.     newpos = self.owner.origin + '0 0 16' + (v_forward * 20) + (v_forward * self.tracbeam_length);
  32. //    newpos = self.owner.origin + (v_forward * 20) + (v_forward * self.tracbeam_length);
  33.  
  34. // Check if new position is possible. If not don't do the move.
  35. // Check if move will bring entities too close together.
  36.     min_dist = vlen(self.owner.maxs) + vlen(self.victim.maxs);
  37.     dist = vlen(self.owner.origin - self.victim.origin);
  38.     if (dist <= min_dist)
  39.     {
  40. // Make warning sound.
  41.         sound (self, CHAN_ITEM, "weapons/beep1.wav", 1, ATTN_NORM);
  42.         self.nextthink = 0.1;
  43.         return;
  44.     }
  45.  
  46. // Check if each extreme of the victim's bounding box is visible. 8 points.
  47. // 1
  48.     checkpoint = newpos + self.victim.maxs;
  49.     traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  50.     if(trace_fraction == 1)
  51.     {
  52. // 2
  53.         checkpoint = newpos +
  54.                      '1 0 0' * self.victim.maxs_x +
  55.                      '0 1 0' * self.victim.mins_y +
  56.                      '0 0 1' * self.victim.maxs_z;
  57.         traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  58.  
  59.         if(trace_fraction == 1)
  60.         {
  61. // 3
  62.             checkpoint = newpos +
  63.                          '1 0 0' * self.victim.maxs_x +
  64.                          '0 1 0' * self.victim.maxs_y +
  65.                          '0 0 1' * self.victim.mins_z;
  66.             traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  67.  
  68.             if(trace_fraction == 1)
  69.             {
  70. // 4
  71.                 checkpoint = newpos +
  72.                              '1 0 0' * self.victim.maxs_x +
  73.                              '0 1 0' * self.victim.mins_y +
  74.                              '0 0 1' * self.victim.mins_z;
  75.                 traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  76.  
  77.                 if(trace_fraction == 1)
  78.                 {
  79. // 5
  80.                     checkpoint = newpos +
  81.                                  '1 0 0' * self.victim.mins_x +
  82.                                  '0 1 0' * self.victim.maxs_y +
  83.                                  '0 0 1' * self.victim.maxs_z;
  84.                     traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  85.  
  86.                     if(trace_fraction == 1)
  87.                     {
  88. // 6
  89.                         checkpoint = newpos +
  90.                                      '1 0 0' * self.victim.mins_x +
  91.                                      '0 1 0' * self.victim.mins_y +
  92.                                      '0 0 1' * self.victim.maxs_z;
  93.                         traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  94.  
  95.                         if(trace_fraction == 1)
  96.                         {
  97. // 7
  98.                             checkpoint = newpos +
  99.                                          '1 0 0' * self.victim.mins_x +
  100.                                          '0 1 0' * self.victim.maxs_y +
  101.                                          '0 0 1' * self.victim.mins_z;
  102.                             traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  103.  
  104.                             if(trace_fraction == 1)
  105.                             {
  106. // 8
  107.                                 checkpoint = newpos + self.victim.mins;
  108.                                 traceline(self.owner.origin, checkpoint, TRUE, self.victim);
  109.  
  110.                                 if(trace_fraction == 1)
  111.                                 {
  112. // Move victim.
  113.                                     setorigin(self, newpos);
  114.                                     setorigin(self.victim, newpos);
  115.                                 }
  116.                             }
  117.                         }
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.     }
  123.  
  124. // Rotate victim with beam.
  125. //    self.angles = vectoangles(v_forward);
  126. //    self.victim.angles = vectoangles(v_forward);
  127.  
  128.     self.nextthink = 0.1;
  129. };
  130.  
  131. void() W_FireTracbeam =
  132. {
  133.     local    vector    org;
  134.     local    entity    tracbeam_ent;
  135.  
  136.     if (self.ammo_cells < 1)
  137.     {
  138.         self.weapon = W_BestWeapon ();
  139.         W_SetCurrentAmmo ();
  140.         return;
  141.     }
  142.  
  143. // explode if under water
  144.     if (self.waterlevel > 1)
  145.     {
  146.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  147.         self.ammo_cells = 0;
  148.         W_SetCurrentAmmo ();
  149.         return;
  150.     }
  151.  
  152.     if (self.t_width < time)
  153.     {
  154.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  155.         self.t_width = time + 0.6;
  156.     }
  157.     self.punchangle_x = -2;
  158.  
  159.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  160.  
  161.     org = self.origin + '0 0 16';
  162.  
  163. // Make the beam stop at the victim entity.
  164.     if(self.tracbeam_status == TRACBEAM_ON)
  165.     {
  166.         traceline (org, org + v_forward * self.tracbeam_length, TRUE, self);
  167.     }
  168.     else
  169.     {
  170.         traceline (org, org + v_forward * TRACBEAM_LEN, TRUE, self);
  171.     }
  172.  
  173.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  174.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  175.     WriteEntity (MSG_BROADCAST, self);
  176.     WriteCoord (MSG_BROADCAST, org_x);
  177.     WriteCoord (MSG_BROADCAST, org_y);
  178.     WriteCoord (MSG_BROADCAST, org_z);
  179.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  180.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  181.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  182.  
  183.     traceline (org, org + v_forward * TRACBEAM_LEN, FALSE, self);
  184.  
  185.     if(self.tracbeam_status == TRACBEAM_ON)
  186.     {
  187. //    Extend the lifespan of the tractorbeam entity.
  188.         self.tracbeam_time = time + 0.3;
  189.     }
  190.     else if(trace_ent.takedamage &&
  191.             trace_ent.movetype != MOVETYPE_NONE &&
  192.             trace_ent.classname != "flame1" &&
  193.             trace_ent.classname != "flame2" &&
  194.             trace_ent.classname != "flamer_bubble" &&
  195.             trace_ent.classname != "bubble" &&
  196.             trace_ent.classname != "trigger_multiple" &&
  197.             trace_ent.classname != "door")
  198.     {
  199. //    Create the tracbeam entity.
  200.         self.tracbeam_status = TRACBEAM_ON;
  201.         self.tracbeam_time = time + 0.3;
  202.         self.tracbeam_length = TRACBEAM_LEN * trace_fraction;
  203.  
  204.         tracbeam_ent = spawn();
  205.         tracbeam_ent.solid = SOLID_NOT;
  206.         setsize(tracbeam_ent, VEC_ORIGIN, VEC_ORIGIN );
  207.         setorigin(tracbeam_ent, trace_ent.origin );
  208.         tracbeam_ent.owner = self;
  209.         tracbeam_ent.victim = trace_ent;
  210.         tracbeam_ent.tracbeam_length = TRACBEAM_LEN * trace_fraction;
  211.  
  212.         tracbeam_ent.think = TracbeamThink;
  213.         tracbeam_ent.nextthink = 0.1;
  214.  
  215. //        trace_ent.movetype = MOVETYPE_TOSS;   causes a bug with items that are not meant to move like barrels.
  216.     }
  217. };
  218.  
  219.